package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.LearningLessonvo;

import com.tianji.learning.domain.Vo.LearningPlanPageVO;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;

import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 学生课表 控制器
 * </p>
 *
 * @author xjs
 */
@Api(tags = "LearningLesson管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/lessons")
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;


    /**
     * 我的课表分页查询
     */
    @ApiOperation("我的课表分页查询")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> page(PageQuery query) {
        return learningLessonService.pageQuery(query);
    }

    @ApiOperation("查询正在学习的课程")
    @GetMapping("/now")
    public LearningLessonVO now() {

        return learningLessonService.now();
    }

    @DeleteMapping("/{courseId}")
    @ApiOperation("删除指定课程信息")
    public void deleteCourseFromLesson(
            @ApiParam(value = "课程id", example = "1") @PathVariable("courseId") Long courseId) {
        learningLessonService.deleteCourseFromLesson(null, courseId);
    }

    @ApiOperation("校验当前课程是否已经报名")
    @GetMapping("/{courseId}/valid")
    public Long isLessonValid(
            @ApiParam(value = "课程id", example = "1") @PathVariable("courseId") Long courseId) {
        return learningLessonService.isLessonValid(courseId);
    }

    @ApiOperation("查询用户课表中指定课程状态")
    @GetMapping("/{courseId}")
    public LearningLessonvo getLessonStatusByUserAndCourseId(@PathVariable String courseId) {
        return learningLessonService.getLessonStatus(courseId);
    }
    /**
     * 统计课程学习人数
     * @param courseId 课程id
     * @return 学习人数
     */
    @GetMapping("/lessons/{courseId}/count")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return learningLessonService.countLearningLessonByCourse(courseId);
    }

    /**
     * 创建学习计划
     *
     */
    @PostMapping("/plans")
    public void plans(@RequestBody LearningPlanDTO dto){
        learningLessonService.plan(dto);
    }
    @GetMapping("/plans")
    public LearningPlanPageVO getPlans(PageQuery query){
        return learningLessonService.getPlans(query);
    }
}
